/*
 * Copyright (C) 2008  Wang Hoi <fearee@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US
*/
#ifndef CONNECTION_H
#define CONNECTION_H
#include "buffer.h"
#include <QtCore>
#include <QtNetwork>
class Buffer;
class Connection: public QObject
{
    Q_OBJECT
public:
    Connection(QTcpSocket *, Server *);
    ~Connection();
    void disconnectFromHost();
    QAbstractSocket::SocketError error() const;
Q_SIGNALS:
    void error(QAbstractSocket::SocketError);
    void disconnected();
public Q_SLOTS:
    void onReadyRead();
    void onBytesWritten(qint64);
    void onDataGot(quint64, const QByteArray&);
    void onUnderBuffer(quint64);
private:
    Server *srv;
    Buffer *srcBuffer;
    qint64 currentPos;
    QString reqURI;
    qint64 reqTime;
    QTcpSocket *socket;
};
#endif
